#include <bits/stdc++.h>

using namespace std;
vector<vector<int>> s;

void get_sequences(vector<int> &a, int n, int t[]) {
    if (a.size() == n) {
        vector<int> b;
        for (int i = 0; i < a.size(); i++) b.push_back(a[i]);
        s.push_back(b);
        return;
    }
    for (int j = 0; j < n; j++) {
        if (t[j]) continue;
        t[j] = 1;
        a.push_back(j);
        get_sequences(a, n, t);
        a.pop_back();
        t[j] = 0;
    }


}

int main() {
    int rank[] = {1, 2, 3, 4};
    string colors[] = {"red", "purple", "blue", "green"};
    vector<int> a;
    int t[4] = {0};
    get_sequences(a, 4, t);
    for (int i0 = 0; i0 < s.size(); i0++) {
        for(int i1 = 0;i1 < s.size();i1++){
            if (1 == s[i0][1] && 2 != s[i0][3] &&
            s[i0][0] != 0 && s[i0][0] != 1 && s[i0][3] != 0 && s[i0][3] != 1
            ){
                int blue = s[i1][2];
                int green = s[i1][3];
                int purple = s[i1][1];
                int br = -1,pr = -1,gr = -1;
                int fr = -1;
                for(int j = 1;j <= s[i0].size();j++){
                    if (blue == s[i0][j]){
                        br = j;
                    }
                    else if (green == s[i0][j]){
                        gr = j;
                    }
                    else if (purple == s[i0][j]){
                        pr = j;
                    }
                    else if (3 == s[i0][j]){
                        fr = j;
                    }
                }
                if (br > fr && gr > pr){
                    cout << s[i0][1] << endl;
                }

            }
        }
    }
}
